<?php

namespace App\Modules\Mq\Tasks;

class AdTimingPushTask extends TaskAbstract
{
    public $service;

    public $wCupRechargeUrl = '';// 广告推送

    public function __construct()
    {
        $this->wCupRechargeUrl = env('APP_URL') . '/ad/timing_push';
    }

    public function process(array $body): bool
    {
        //记录入口日志
        self::addLog("request", $body);

        $pushId = $body['push_id'] ?? 0;
        $state = false;

        if ($pushId > 0) {
            $url = $this->wCupRechargeUrl;
            $params = [];
            $params['id'] = $pushId;
            $res = curl_request($url, $params, 'urlencoded', 'GET');
            if ($res) {
                $resJson = json_decode($res, true);
                if ($resJson && isset($resJson['code']) && $resJson['code'] == 0) {
                    $state = true;
                }
            }
        }

        self::addLog("广告定时推送任务", $body, ['state' => $state, 'res' => $res ?? '']);

        return $state;

    }
}
